<?
/**
 * 对外的操作
 */
 class review_dwr
 {
 	public $db;
 	public $vars;
 	public $table;
 	public function __construct()
 	{
 	    global $scfg;
 	    $this->db 	= new db($scfg['db']['msg']);
 	    $this->table= "pct_review";
 		$this->vars = &$_GET;//&$_POST;
 	}
 	public function insert()
 	{
 		if(urs)
 		{
	 		$pct		= $this->vars["pct"];
	 		$data_id	= $this->vars["data_id"];
	 		$data_urs   = $this->vars["data_urs"];
	 		$contents   = $this->vars["contents"];
	 		$verifycode = $this->vars["verifycode"];
	 		$authimg_idcode = $_COOKIE["idcode"];
	 		if(authimg::de($authimg_idcode) == $verifycode)
	 		{
	 			!is_numeric($data_id) && $data_id = g::phpDeCode($data_id);
	 			$bind =array(
	 				"pct" =>$pct,
	 				"data_id"=>$data_id,
	 				"data_urs"=>$data_urs,
	 				"urs"=>urs,
	 				"contents"=>$contents,
	 				"save_time"=>time(),
	 				"ip"=>g::ip() 				
	 			);
	 			$rs = $this->db->insert($this->table,$bind);
	 			if($rs)
	 			{
	 			    $rs = array(1,"成功:发表留言成功!");
	 			}else
	 			{
	 			    $rs = array(0,"提示:系统忙,稍后请重试!");
	 			}
	 		}else
	 		{
	 		    $rs = array(0,"提示:图形认证码有误!");
	 		}
		}else
 		{
 		    $rs = array(1,"提示:请先登录后才可以进行留言!");
 		}
 		echo json::flush($rs);
 	}
 	public function review()
 	{
 		if(urs)
 		{
 		    $pct		= $this->vars["pct"];
	 		$data_id	= $this->vars["data_id"];
	 		$id			= $this->vars["id"];
	 		$data_urs   = $this->vars["data_urs"];
	 		$contents   = $this->vars["contents"];
	 		!is_numeric($data_id) && $data_id = g::phpDeCode($data_id);
	 		$bind =array(
 				"review"=>$contents,
 				"review_time"=>time(),
 			);
 			$rs = $this->db->update($this->table,$bind," id = :id and data_urs = :data_urs ",array("id"=>$id,"data_urs"=>$data_urs));
 			if($rs)
 			{
 			    $rs = array(1,"成功:发表留言成功!");
 			}else
 			{
 			    $rs = array(0,"提示:操作错误或系统忙!");
 			}
 		}else
 		{
 		    $rs = array(0,"提示:请先登录后才可以进行留言!");
 		}
 		echo json::flush($rs); 		
 	}
 	public function del()
 	{
 	    if(urs)
 		{
 		    $id			= $this->vars["id"];
	 		$rs 		= $this->db->delete($this->table," id = :id and (data_urs = :data_urs or urs = :urs) ",array("id"=>$id,"data_urs"=>urs,"urs"=>urs));
 			if($rs)
 			{
 			    $rs = array(1,"成功:删除成功!");
 			}else
 			{
 			    $rs = array(0,"提示:操作错误或系统忙!");
 			}
 		}else
 		{
 		    $rs = array(0,"提示:请先登录后才可以进行操作!");
 		}
 		echo json::flush($rs);
 	}
 	public function pct()
 	{
 		$pct		= $this->vars["pct"];
 		$data_id	= $this->vars["data_id"];
 		$data_urs   = $this->vars["data_urs"];
 		$page   	= $this->vars["page"];
 		$rows 		= $this->vars["rows"];
 		!is_numeric($data_id) && $data_id = g::phpDeCode($data_id);
 		$where      = array(
 			"where" => " where pct = :pct and data_id = :data_id ",
 			"bind"  => array(
 				"pct"=>$pct,
 				"data_id"=>$data_id
 			)
 		);
 		$rs			= $this->db->row("select count(id) as cc from {$this->table} {$where['where']} ",$where['bind']);
 		$rs			= array(
 			"all" =>$rs["cc"],
 			"this"=>$page,
 			"pgc" =>ceil($rs["cc"]/$rows),
 			"data"=>$this->db->dataArray("select * from {$this->table} {$where['where']} order by id desc limit ".($page*$rows-$rows).",".$rows,$where['bind'])
 		);
 		echo json::flush($rs); 		
 	}
 	public function urs()
 	{
 		$pct		= $this->vars["pct"];
 		$data_id	= $this->vars["data_id"];
 		$data_urs   = $this->vars["data_urs"];
 		$page   	= $this->vars["page"];
 		$rows 		= $this->vars["rows"];
 		//!is_numeric($data_id) && $data_id = g::phpDeCode($data_id);
 		$where      = array(
 			"where" => " where data_urs = :data_urs ",
 			"bind"  => array(
 				"data_urs"=>$data_urs
 			)
 		);
 		$rs			= $this->db->row("select count(id) as cc from {$this->table} {$where['where']} ",$where['bind']);
 		$rs			= array(
 			"all" =>$rs["cc"],
 			"this"=>$page,
 			"pgc" =>ceil($rs["cc"]/$rows),
 			"data"=>$this->db->dataArray("select * from {$this->table} {$where['where']} order by id desc limit ".($page*$rows-$rows).",".$rows,$where['bind'])
 		);
 		echo json::flush($rs); 
 	}
 	public function me()
 	{
 		$pct		= $this->vars["pct"];
 		$data_id	= $this->vars["data_id"];
 		$data_urs   = $this->vars["data_urs"];
 		$urs   		= $this->vars["urs"];
 		$page   	= $this->vars["page"];
 		$rows 		= $this->vars["rows"];
 		//!is_numeric($data_id) && $data_id = g::phpDeCode($data_id);
 		$where      = array(
 			"where" => " where urs = :urs ",
 			"bind"  => array(
 				"urs"=>$urs?$urs:$data_urs,
 			)
 		);
 		$rs			= $this->db->row("select count(id) as cc from {$this->table} {$where['where']} ",$where['bind']);
 		$rs			= array(
 			"all" =>$rs["cc"],
 			"this"=>$page,
 			"pgc" =>ceil($rs["cc"]/$rows),
 			"data"=>$this->db->dataArray("select * from {$this->table} {$where['where']} order by id desc limit ".($page*$rows-$rows).",".$rows,$where['bind'])
 		);
 		echo json::flush($rs); 
 	}
 }
 /**
  * 下面是程序路由
  */
  
 //echo basename(__FILE__);
 //echo "<br />";
 //echo basename($_SERVER["SCRIPT_FILENAME"]);
 if(basename(__FILE__) == basename($_SERVER["SCRIPT_FILENAME"]))
 {
	 require('../inc.php');
	 $Pact       = $_REQUEST["Pact"];
	 if($Pact)
	 {
		 $class = 'review_dwr';
		 if (class_exists($class))
		 {
			$class = new $class();
			if(method_exists($class,$Pact))
			{
				$class->$Pact();		
			}else
			{
				echo "NO_THIS_ACTION";
			}
		 }else
		 {
			echo "NO_THIS_MOUDLE";
		 }
	 }else
	 {
	 	echo "NO_THIS_PACTION";
	 }
 }
 exit();
?>